package com.wz.project.bas.department.controller;

import com.wz.framework.web.controller.BaseController;
import com.wz.framework.web.domain.AjaxResult;
import com.wz.framework.web.page.TableDataInfo;
import com.wz.project.bas.department.domain.Department;
import com.wz.project.bas.department.service.IDepartmentService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 领用部门 信息操作处理
 * 
 * @author sys
 * @date 2021-10-28
 */
@Controller
@RequestMapping("/bas/department")
public class DepartmentController extends BaseController
{
    private String prefix = "bas/department";
	
	@Autowired
	private IDepartmentService departmentService;
	
	@RequiresPermissions("bas:department:view")
	@GetMapping()
	public String department()
	{
	    return prefix + "/department";
	}
	
	/**
	 * 查询领用部门列表
	 */
//	@RequiresPermissions("module:department:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Department department)
	{
		startPage();
        List<Department> list = departmentService.selectDepartmentList(department);
		return getDataTable(list);
	}
	
	/**
	 * 新增领用部门
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存领用部门
	 */
	@RequiresPermissions("module:department:add")
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Department department)
	{
		String s = String.valueOf(System.currentTimeMillis());
		String substring = s.substring(s.length() - 6);
//        int pejId = Integer.parseInt(substring);
		department.setDepartmentId(substring);
		return toAjax(departmentService.insertDepartment(department));
	}

	/**
	 * 修改领用部门
	 */
	@GetMapping("/edit/{departmentId}")
	public String edit(@PathVariable("departmentId") String departmentId, ModelMap mmap)
	{
		Department department = departmentService.selectDepartmentById(departmentId);
		mmap.put("department", department);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存领用部门
	 */
	@RequiresPermissions("module:department:edit")
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Department department)
	{		
		return toAjax(departmentService.updateDepartment(department));
	}
	
	/**
	 * 删除领用部门
	 */
	@RequiresPermissions("module:department:remove")
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(departmentService.deleteDepartmentByIds(ids));
	}
	
}
